package bosque.unc.gui;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.UIManager;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class GraficoConfigGUI extends JFrame {

	private JPanel contentPane;
	private JTextField textFieldLargoTelescopio;
	private JTextField textFieldRadioCupula;
	private JTextField textFieldAnchoRanura;
	private JTextField textFieldOffsetRanura;
	
	private static Scoba scoba;	
	
	private JButton btnCargarValores;
	private JButton btnGuardarValores;
	private JButton btnActualizarValores;
	private JButton btnActualizarGrafico;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				
				try
				{
					System.out.println("Look and Fell: " + UIManager.getSystemLookAndFeelClassName());
					UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
				}
				catch (Exception ex)
				{
					System.out.println("Failed loading L&F: ");
					System.out.println(ex);
				}
				
				try {
					GraficoConfigGUI frame = new GraficoConfigGUI(scoba);
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public GraficoConfigGUI(Scoba sco) 
	{
		
		inicializarVentana(sco);
	}
	
	public void inicializarVentana(Scoba sco)
	{
		scoba = sco ;
		setTitle("Modificacion del Grafico");
		setResizable(false);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JLabel lblLargoDelTelescopio = new JLabel("Largo del Telescopio: ");
		lblLargoDelTelescopio.setBounds(10, 34, 112, 14);
		contentPane.add(lblLargoDelTelescopio);
		
		textFieldLargoTelescopio = new JTextField();
		textFieldLargoTelescopio.setBounds(132, 31, 59, 20);
		contentPane.add(textFieldLargoTelescopio);
		textFieldLargoTelescopio.setColumns(10);
		
		JLabel lblRadioCupulaDibujo = new JLabel("Radio Cupula Dibujo:");
		lblRadioCupulaDibujo.setBounds(10, 86, 112, 14);
		contentPane.add(lblRadioCupulaDibujo);
		
		textFieldRadioCupula = new JTextField();
		textFieldRadioCupula.setBounds(132, 83, 59, 20);
		contentPane.add(textFieldRadioCupula);
		textFieldRadioCupula.setColumns(10);
		
		JLabel lblAnchoDeLa = new JLabel("Ancho de la Ranura:");
		lblAnchoDeLa.setBounds(10, 143, 112, 14);
		contentPane.add(lblAnchoDeLa);
		
		textFieldAnchoRanura = new JTextField();
		textFieldAnchoRanura.setColumns(10);
		textFieldAnchoRanura.setBounds(132, 140, 59, 20);
		contentPane.add(textFieldAnchoRanura);
		
		textFieldOffsetRanura = new JTextField();
		textFieldOffsetRanura.setColumns(10);
		textFieldOffsetRanura.setBounds(132, 193, 59, 20);
		contentPane.add(textFieldOffsetRanura);
		
		JLabel lblOffsetDeLa = new JLabel("Offset de la Ranura:");
		lblOffsetDeLa.setBounds(10, 196, 112, 14);
		contentPane.add(lblOffsetDeLa);
		
		btnCargarValores = new JButton("Cargar Valores");
		btnCargarValores.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
				textFieldLargoTelescopio.setText(scoba.getGraficoGUI().getLargoTelescopio().toString());
				textFieldRadioCupula.setText(scoba.getGraficoGUI().getRadioCupulaDibujo().toString());
				textFieldAnchoRanura.setText(scoba.getGraficoGUI().getRanuraAnchoDibujo().toString());
				textFieldOffsetRanura.setText(scoba.getGraficoGUI().getRanuraOffsetCentroDibujo().toString());
			}
		});
		btnCargarValores.setBounds(293, 82, 112, 23);
		contentPane.add(btnCargarValores);
		
		btnGuardarValores = new JButton("Guardar Valores");
		btnGuardarValores.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {

				scoba.guardarConfiguracion();
			}
		});
		btnGuardarValores.setBounds(293, 139, 112, 23);
		contentPane.add(btnGuardarValores);
		
		btnActualizarValores = new JButton("Resetear Valores");
		btnActualizarValores.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
				scoba.getGraficoGUI().setLargoTelescopio((Double.parseDouble(getTextFieldLargoTelescopio().getText())));
				scoba.getGraficoGUI().setRadioCupulaDibujo((Double.parseDouble(getTextFieldRadioCupula().getText())));
				scoba.getGraficoGUI().setRanuraAnchoDibujo((Double.parseDouble(getTextFieldAnchoRanura().getText())));
				scoba.getGraficoGUI().setRanuraOffsetCentroDibujo((Double.parseDouble(getTextFieldOffsetRanura().getText())));
				
				
			}
		});
		btnActualizarValores.setBounds(285, 192, 130, 23);
		contentPane.add(btnActualizarValores);
		
		btnActualizarGrafico = new JButton("Actualizar Grafico");
		btnActualizarGrafico.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
				
				scoba.getGraficoGUI().setLargoTelescopio( Double.parseDouble( textFieldLargoTelescopio.getText()));
				scoba.getGraficoGUI().setRadioCupulaDibujo(Double.parseDouble(textFieldRadioCupula.getText()));
				scoba.getGraficoGUI().setRanuraAnchoDibujo( Double.parseDouble(textFieldAnchoRanura.getText()));
				scoba.getGraficoGUI().setRanuraOffsetCentroDibujo( Double.parseDouble(textFieldOffsetRanura.getText()));
				scoba.getGraficoGUI().repaint();
			}
		});
		btnActualizarGrafico.setBounds(285, 30, 130, 23);
		contentPane.add(btnActualizarGrafico);
	}

	public JTextField getTextFieldLargoTelescopio() {
		return textFieldLargoTelescopio;
	}

	public void setTextFieldLargoTelescopio(JTextField textFieldLargoTelescopio) {
		this.textFieldLargoTelescopio = textFieldLargoTelescopio;
	}

	public JTextField getTextFieldRadioCupula() {
		return textFieldRadioCupula;
	}

	public void setTextFieldRadioCupula(JTextField textFieldRadioCupula) {
		this.textFieldRadioCupula = textFieldRadioCupula;
	}

	public JTextField getTextFieldAnchoRanura() {
		return textFieldAnchoRanura;
	}

	public void setTextFieldAnchoRanura(JTextField textFieldAnchoRanura) {
		this.textFieldAnchoRanura = textFieldAnchoRanura;
	}

	public JTextField getTextFieldOffsetRanura() {
		return textFieldOffsetRanura;
	}

	public void setTextFieldOffsetRanura(JTextField textFieldOffsetRanura) {
		this.textFieldOffsetRanura = textFieldOffsetRanura;
	}
	
	
	
	
	
}
